home *** CD-ROM | disk | FTP | other *** search
/ The Complete Utilities To…ka 501 Killer Utilities! / 501 Killer Utilities! (Macworld July 1995).cdr / Programming / OutOfPhase1.1 Source / OutOfPhase Folder / 64BitMath.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-04  |  3.2 KB  |  109 lines  |  [TEXT/KAHL]

  1. /* 64BitMath.h */
  2.  
  3. #ifndef Included_64BitMath_h
  4. #define Included_64BitMath_h
  5.  
  6. /* 64BitMath module depends on */
  7. /* MiscInfo.h */
  8. /* Audit */
  9. /* Debug */
  10. /* Definitions */
  11.  
  12.  
  13. #if defined(__GNUC__) /* || sizeof(long) == 8 */
  14.  
  15.  
  16. #define STRUCTUREBASED64BIT (0)
  17.  
  18. #if defined(__GNUC__)
  19.     /* this is the GNU stuff */
  20.     typedef long long int LongLongRec;
  21. #else
  22.     /* if sizeof(long) == 8 then you can enable this */
  23.     typedef long int LongLongRec;
  24. #endif
  25.  
  26. /* initialize a longlong with a double precision floating point value */
  27. #define Double2LongLong(dbl,lnglng) ((void)((lnglng)\
  28.                     = (LongLongRec)((dbl) * 4294967296.0L)))
  29.  
  30. /* convert a longlong to a double precision floating point value */
  31. #define LongLong2Double(lnglng) ((double)(lnglng) / 4294967296.0L)
  32.  
  33. /* get the low order unsigned 32 bits from the longlong */
  34. #define LongLongLowHalf(lnglng) ((unsigned long)((lnglng) & 0x00000000ffffffff))
  35.  
  36. /* get the high order signed 32 bits from the longlong */
  37. #define LongLongHighHalf(lnglng) ((signed long)((lnglng) >> 32))
  38.  
  39. /* mask the upper word */
  40. #define LongLongMaskHighHalf(lnglng,mask32) ((void)((lnglng) = ((((LongLongRec)(mask32))\
  41.                     << 32) | 0x00000000ffffffff) & (lnglng)))
  42.  
  43. /* store a new value into the upper word */
  44. #define LongLongSetHighHalf(lnglng,newhi) ((void)((lnglng) = (((LongLongRec)(newhi))\
  45.                     << 32) | ((lnglng) & 0x00000000ffffffff)))
  46.  
  47. /* add two longlongs:  *L = *L + *R */
  48. #define LongLongAdd(L,R) ((void)(*(L) = *(L) + *(R)))
  49.  
  50.  
  51. #else
  52.  
  53.  
  54. #define STRUCTUREBASED64BIT (1)
  55.  
  56. /* stuff for systems with only 32 bit ints */
  57.  
  58. /* set this to 1 to always use the generic add */
  59. #define FORCEGENERIC64BITADD (0)
  60.  
  61. /* this is publicly visible for speed */
  62. typedef struct LongLongRec
  63.     {
  64.         unsigned long                Low32Bits;
  65.         signed long                    High32Bits;
  66.     } LongLongRec;
  67.  
  68. /* initialize a longlong with a double precision floating point value */
  69. void                            Double2LongLong(double D, LongLongRec* L);
  70.  
  71. /* convert a longlong to a double precision floating point value */
  72. #define LongLong2Double(lnglng) ((lnglng).High32Bits\
  73.                     + (lnglng).Low32Bits / 4294967296.0L)
  74.  
  75. /* get the low order unsigned 32 bits from the longlong */
  76. #define LongLongLowHalf(lnglng) ((lnglng).Low32Bits)
  77.  
  78. /* get the high order signed 32 bits from the longlong */
  79. #define LongLongHighHalf(lnglng) ((lnglng).High32Bits)
  80.  
  81. /* mask the upper word */
  82. #define LongLongMaskHighHalf(lnglng,mask32) ((void)((lnglng).High32Bits &= (mask32)))
  83.  
  84. /* store a new value into the upper word */
  85. #define LongLongSetHighHalf(lnglng,newhi) ((void)((lnglng).High32Bits = (newhi)))
  86.  
  87. /* add two longlongs:  *L = *L + *R */
  88. #if !FORCEGENERIC64BITADD && defined(THINK_C)
  89.     /* 00000000: 2019               MOVE.L    (A1)+,D0 */
  90.     /* 00000002: D198               ADD.L     D0,(A0)+ */
  91.     /* 00000004: 2211               MOVE.L    (A1),D1 */
  92.     /* 00000006: 2010               MOVE.L    (A0),D0 */
  93.     /* 00000008: D181               ADDX.L    D1,D0 */
  94.     /* 0000000A: 2080               MOVE.L    D0,(A0) */
  95.     #pragma parameter LongLongAdd(__A0,__A1)
  96.     void                            LongLongAdd(LongLongRec* L, LongLongRec* R)
  97.         = {0x2019, 0xD198, 0x2211, 0x2010, 0xD181, 0x2080};
  98.     #define ENABLEGENERICLONGLONG (0)
  99. #else
  100.     void                            LongLongAdd(LongLongRec* L, LongLongRec* R);
  101.     #define ENABLEGENERICLONGLONG (1)
  102. #endif
  103.  
  104.  
  105. #endif
  106.  
  107.  
  108. #endif
  109.